package com.campus.config;


import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;

import static com.campus.common.BusinessConstants.ENCODING;

/**
 * @desc: DispatcherServlet:
 * @author: Ping
 * @date: 2024/10/21 14:51
 */

public class MyDispacherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{ServletContextConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    @Override
    protected Filter[] getServletFilters() {
        // 处理乱码问题
        return new Filter[]{new CharacterEncodingFilter(ENCODING, true)};
    }
}
